﻿using AppGPS.Helper;
using Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace AppGPS.ViewModels
{
    class UserInfoRequest
    {
        string _host = App.dataShare.szHost;
        APIRequest<UserInfoRequest> _apiUserInfo = new APIRequest<UserInfoRequest>();
        public UserInfoRequest(string Host)
        {
            _host = Host;
        }
        public async Task<bool> EmailExists(string Email)
        {
            var Result = await _apiUserInfo.GetRequestAsync(_host, "api/userinfo/GetByEmail?Email=" + Email);

            if (Result == null) return false;
            else
                return true;
        }
        public async Task<bool> UpdateInfomation(UserResult data)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_host);
                var json = JsonConvert.SerializeObject(data);
                StringContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PutAsync("api/userinfo/putupdate", content);
                if (response.IsSuccessStatusCode)
                {
                    return true;
                }

            }
            return false;
        }
    }
}
